package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "微信授权登录接口")
@RestController
@RequestMapping("/api/user/wxLogin")
@Slf4j
public class WxLoginApiController {

    private final UserInfoService userInfoService;

    @Autowired
    public WxLoginApiController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    /**
     * 微信小程序登录
     *
     * @param code
     * @return
     */
    @GetMapping("/wxLogin/{code}")
    public Result wxLongin(@PathVariable("code") String code) {
        return Result.ok(userInfoService.wxLogin(code));
    }


    /**
     * 查询已登录用户的信息
     *
     * @return UserInfoVo
     */
    @GuiguLogin
    @GetMapping("/getUserInfo")
    public Result<UserInfoVo> getUserInfo() {
        return Result.ok(userInfoService.getUserInfo());
    }
}
